<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>sessionStorage</title>
</head>
<body>
    <h1>sessionStorage</h1>
    <button onclick="setData()">点我添加数据</button>
    <button onclick="removeData()">点我删除数据</button>
    <button onclick="getData()">点我获取数据</button>
    <button onclick="clearData()">点我清空数据</button>
    <script>
        
        console.log(window.sessionStorage);
        
        // sessionStorage.setItem(key,value);
        // sessionStorage.removeItem(key);
        // sessionStorage.getItem(key);
        // sessionStorage.clear();
        
        function setData(){
            sessionStorage.setItem('name','小明')
            sessionStorage.setItem('age',19)
            const user = {name:"小明",age:19};
            sessionStorage.setItem('user',JSON.stringify(user));
        }

        function removeData(){
            sessionStorage.removeItem('user');
        }

        function getData(){
            console.log(sessionStorage.getItem('name'))
        }

        function clearData(){
            sessionStorage.clear();
        }
        


    </script>
</body>
</html>